package com.partvoyage.client.outil;

import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.geom.Size;
import com.google.gwt.maps.client.overlay.Icon;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.maps.client.overlay.MarkerOptions;
import com.partvoyage.shared.InfoPointBean.TYPE_ZOOM_LEVEL;
import com.partvoyage.shared.InfoPointBean;
import com.partvoyage.client.mvp2.view.carte.service.CartePresentationService;

public class PointSurLaCarte extends Marker {

	private InfoPointBean info;
	private Boolean focus = false;

	public PointSurLaCarte(InfoPointBean info, Boolean focus) {
		super(LatLng.newInstance(info.getLatitude(), info.getLongitude()),
				getOptions(info, focus));
		this.focus = focus;
		this.info = info;
		this.setDraggingEnabled(true);
	}

	private static MarkerOptions getOptions(InfoPointBean info, Boolean focus) {
		Icon icon = Icon.newInstance(Icon.DEFAULT_ICON);
		if (info.getZoomLevel() == null) {
			if (focus) {
				icon.setImageURL("/images/globetrotter_marker_focus.png");
			} else {
				icon.setImageURL("/images/globetrotter_marker.png");
			}
		} else {
			TYPE_ZOOM_LEVEL zoomLevel = CartePresentationService
					.getZoomLevel(info.getZoomLevel());
			if (zoomLevel.equals(TYPE_ZOOM_LEVEL.PAYS_LEVEL)) {
				if (focus) {
					icon.setImageURL("/images/avion_marker_focus.png");
				} else {
					icon.setImageURL("/images/avion_marker.png");
				}
			} else if (zoomLevel.equals(TYPE_ZOOM_LEVEL.VILLE_LEVEL)) {
				if (focus) {
					icon.setImageURL("/images/voiture_marker_focus.png");
				} else {
					icon.setImageURL("/images/voiture_marker.png");
				}
			} else {
				if (focus) {
					icon.setImageURL("/images/globetrotter_marker_focus.png");
				} else {
					icon.setImageURL("/images/globetrotter_marker.png");
				}

			}
		}
		Size size = Size.newInstance(30, 30);
		icon.setIconSize(size);
		MarkerOptions ops = MarkerOptions.newInstance(icon);
		ops.setIcon(icon);
		ops.setDraggable(true);
		return ops;
	}

	public InfoPointBean getInfo() {
		return info;
	}

	public void setInfo(InfoPointBean info) {
		this.info = info;
	}

}
